<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>solve</title>
<style type="text/css">
	body {background-color: white; color: black; font-family:sans-serif; font-size:medium;}
	a:link {color: #3300ff;}
	a:visited {color: #663399;}
	a:hover {color:#0099ff;}
	a:active {color: #0066cc;}
	a.button {text-decoration:none;}
	
	table.nav  {background-color: #dbddff;}
	table.body {margin-top:2ex; margin-bottom:2ex;}
	table.programlistingindent {margin-left:32px;}
	
	img { margin-bottom:0px; margin-top:0px;}
	tt {margin-left:0.5em; margin-right:0.5em; font-weight:lighter;}
	
	p {margin-top:0ex;}
	p.synopsis {margin-left:32px;}
	p.programlistingindent {margin-left:32px;}
	p.citetitle {margin-left:2em;}
	
	ul ul {list-style-type:square;}
	ul li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	ol li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	
	h1.reftitle {color:#a90000;}
	h1.reftitle {font-size:3.7ex; margin-top:0; margin-bottom:0; font-weight:bold}
	h1.title {color:black; font-size:4ex; margin-top:1ex; font-weight:bold}
	h2.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:3ex}
	h3.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h4.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex}
	h2 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h3 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex} 
	
	pre.programlisting {margin-left:32px;}
	pre.synopsis {margin-left:32px;}
	
	
	.categorytitle {margin-top:8px; padding-top:0px;}
	.categorylist {background-color: #e1e6f2;}
 	</style>
</head>
<body>
<a name="top_of_page"></a><p style="font-size:1px;"></p>
<h1 class="reftitle">solve</h1>
<h2>Purpose</h2>
<p>The main routine for solving optimization problems</p>
<h2>Syntax</h2>
<pre class="synopsis">result = problem.solve</pre>
<pre class="synopsis">result = problem.solve(th)</pre>
<pre class="synopsis">result = solve(problem)</pre>
<h2>Description</h2>
<p></p>
        The main routine for solving non-parametric (LP, QP, MILP, MIQP) and parametric problems (MPLP, MPQP, PLCP).
        The result is returned in the appropriate format depending on the problem.
        
        The <tt>Opt</tt> class serves as general wrapper for preprocessing the data 
        involved in optimization, including necessary error checks. Once the data are valid, 
        then are passed to <tt>mpt_solve</tt> or <tt>mpt_solvemp</tt> function that calls the appropriate solver without
        any errorchecks. <br><br>
        For parametric problems it is possible to solve the problem for a particular value of the parameters <img src="../../../../../fig/mpt/modules/solvers/@Opt/solve1.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/solve1.png">        
        if provided as an argument <tt>th</tt>.

        
	<h2>Input Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody><tr valign="top">
<td><tt>problem</tt></td>
<td>
<p></p> Object of the <tt>Opt</tt> class that defines the optimization problem to be solved. <p>
	    		Class: <tt>Opt</tt></p>
</td>
</tr></tbody>
</table>
<h2>Output Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody>
<tr valign="top">
<td><tt>result</tt></td>
<td>
<p></p>Structure with the date that represents the solution to given problem. For non-parametric problems the solution is returned with
        the following fields.
       <p>
	    		Class: <tt>struct</tt><p></p><tr valign="top">
<td><tt>result.xopt</tt></td>
<td>
<p></p>Optimal solution for primal variables.<p>
	    		Class: <tt>double</tt></p>
</td>
</tr><tr valign="top">
<td><tt>result.obj</tt></td>
<td>
<p></p>Objective value.<p>
	    		Class: <tt>double</tt></p>
</td>
</tr><tr valign="top">
<td><tt>result.lambda</tt></td>
<td>
<p></p>Lagrangian multipliers<p>
	    		Class: <tt>double</tt></p>
</td>
</tr><tr valign="top">
<td><tt>result.exitflag</tt></td>
<td>
<p></p>An integer value that informs if the result was feasible (1), or otherwise (different from 1)<p>
	    		Class: <tt>double</tt></p>
</td>
</tr><tr valign="top">
<td><tt>result.how</tt></td>
<td>
<p></p>A string that informs if the result was feasible ('ok'), or if any problem appeared through optimization<p>
	    		Class: <tt>char</tt></p>
</td>
</tr><p></p></p>
</td>
</tr>
<tr valign="top">
<td><tt>result</tt></td>
<td>
<p></p>Structure with the date that represents the solution to given problem. For parametric problems the solution is returned with
        the following fields.
       <p>
	    		Class: <tt>struct</tt><p></p><tr valign="top">
<td><tt>result.xopt</tt></td>
<td>
<p></p>Optimal solution for variables <img src="../../../../../fig/mpt/modules/solvers/@Opt/solve2.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/solve2.png">, <img src="../../../../../fig/mpt/modules/solvers/@Opt/solve3.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/solve3.png"> from PLCP reformulation if the problem was solved using PLCP solver.
                    If the original problem was given as MPLP/MPQP, then this field returns also primal, dual variables, and the objective value
                    for given problem.
                    The solution is given as a collection of polyhedra in the same dimension with certain properties and is given as 
                    <tt>PolyUnion</tt> class. The function data associated to each variable is stored under <tt>Function</tt>, in particular
                    in <tt>res.Set(i).Func{j}</tt> where the index <img src="../../../../../fig/mpt/modules/solvers/@Opt/solve4.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/solve4.png"> corresponds to <tt>i</tt>-th region and index <img src="../../../../../fig/mpt/modules/solvers/@Opt/solve5.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/solve5.png"> to <tt>j</tt>-th 
                    function. 
                <p>
	    		Class: <tt>PolyUnion</tt></p>
</td>
</tr><tr valign="top">
<td><tt>result.exitflag</tt></td>
<td>
<p></p>An integer value that informs if the result was feasible (1), or otherwise (different from 1)<p>
	    		Class: <tt>double</tt></p>
</td>
</tr><tr valign="top">
<td><tt>result.how</tt></td>
<td>
<p></p>A string that informs if the result was feasible ('ok'), or if any problem appeared through optimization<p>
	    		Class: <tt>char</tt></p>
</td>
</tr><tr valign="top">
<td><tt>result.stats</tt></td>
<td>
<p></p>Other details from the computation that might be of interest, such as the number of pivots, elapsed time, etc.<p>
	    		Class: <tt>struct</tt></p>
</td>
</tr><p></p></p>
</td>
</tr>
</tbody>
</table>
<h2>Example(s)</h2>
<h3>Example 
				1</h3> Solve an LP stored in file <tt>sc50b</tt>. Load the data<pre class="programlisting"> load sc50b </pre>
<pre class="programlisting"></pre> Create the optimization problem using <tt>Opt</tt> class<pre class="programlisting"> problem = Opt('A',A,'b',b,'Ae',Aeq,'be',beq,'lb',lb,'f',f) </pre>
<pre class="programlisting">-------------------------------------------------
Linear program
	Num variables:               48
	Num inequality constraints:  30
	Num equality constraints:    20
	Num lower bounds             48
	Solver:                     LCP
-------------------------------------------------
</pre> Solve the problem <pre class="programlisting"> result = problem.solve </pre>
<pre class="programlisting">
result = 

        xopt: [48x1 double]
      lambda: [1x1 struct]
         obj: -69.9999999999999
         how: 'ok'
    exitflag: 1

</pre>
<h3>Example 
				2</h3> Create random PLCP problem and solve it Generate data <pre class="programlisting"> H = randn(5); M = sqrt(2)*H'*H; q=randn(5,1); Q = randn(5,2); </pre>
<pre class="programlisting"></pre> Provide bounds on the parameters <pre class="programlisting"> Ath = randn(8,2); bth = 5*ones(8,1); </pre>
<pre class="programlisting"></pre> Construct the problem <pre class="programlisting"> problem = Opt('M',M,'q',q,'Q',Q,'Ath',Ath,'bth',bth); </pre>
<pre class="programlisting"></pre> Solve the problem <pre class="programlisting"> result = problem.solve </pre>
<pre class="programlisting">mpt_plcp: 10 regions

result = 

        xopt: [1x1 PolyUnion]
    exitflag: 1
         how: 'ok'
       stats: [1x1 struct]

</pre> We can plot the solution <pre class="programlisting"> result.xopt.plot </pre>
<pre class="programlisting"></pre>
<p class="programlistingindent"><img src="../../../../../fig/mpt/modules/solvers/@Opt/solve_img_1.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/solve_img_1.png" width="60%"></p>
<h3>Example 
				3</h3> Formulate linear parametric problem <img src="../../../../../fig/mpt/modules/solvers/@Opt/solve6.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/solve6.png">
            with the help of YALMIP.
        <pre class="programlisting"> sdpvar x1 x2 th </pre>
<pre class="programlisting"></pre> Objective function: <pre class="programlisting">  obj = x1-2*x2*th+th; </pre>
<pre class="programlisting"></pre> Constraints: <pre class="programlisting">  F = [ x1-x2 &gt;= th; x1&gt;=0; x2&gt;=0; -1&lt;= th &lt;= 1]; </pre>
<pre class="programlisting"></pre> Construct an instance of <tt>Opt</tt> class that represents parametric linear program <pre class="programlisting"> problem=Opt(F,obj,th,[x1;x2]) </pre>
<pre class="programlisting">-------------------------------------------------
Parametric linear program
	Num variables:                2
	Num inequality constraints:   5
	Num equality constraints:     0
	Num lower bounds              2
	Num upper bounds              2
	Num parameters:               1
	Solver:                     PLCP
-------------------------------------------------
</pre> Solve the above problem quickly for the point <tt>th=0.5</tt> without generating explicit solution
        <pre class="programlisting"> problem.solve(0.5) </pre>
<pre class="programlisting">
ans = 

        xopt: [2x1 double]
      lambda: [1x1 struct]
         obj: 1
         how: 'ok'
    exitflag: 1

</pre> Verify this result by solving the problem parametrically<pre class="programlisting"> res=problem.solve; </pre>
<pre class="programlisting">mpt_plcp: 2 regions
</pre>  Plot the optimal cost function <pre class="programlisting"> res.xopt.fplot('obj','linewidth',3); </pre>
<pre class="programlisting"></pre>
<p class="programlistingindent"><img src="../../../../../fig/mpt/modules/solvers/@Opt/solve_img_2.png" alt="../../../../../fig/mpt/modules/solvers/@Opt/solve_img_2.png" width="60%"></p> Evaluate the explicit solution for the point <tt>th=0.5</tt> 
      <pre class="programlisting"> res.xopt.feval(0.5,'obj') </pre>
<pre class="programlisting">
ans =

     1

</pre>
<h2>See Also</h2>
<a href="./opt.html">opt</a>, <a href="../mpt_solve.html">mpt_solve</a>, <a href="../mpt_solvemp.html">mpt_solvemp</a><p></p>
<table class="nav" summary="Navigation aid" border="0" width="100%" cellpadding="0" cellspacing="0"><tr valign="top">
<td align="left" width="20">
<a href="display.html" class="button">&#9664;</a>  </td>
<td align="left">display</td>
<td>  </td>
<td align="right">feasibleset</td>
<td align="right" width="20"><a href="feasibleset.html" class="button">&#9654;</a></td>
</tr></table>
<br><p>©  <b>2010-2013</b>     Martin Herceg: ETH Zurich,    <a href="mailto:herceg@control.ee.ethz.ch">herceg@control.ee.ethz.ch</a></p>
</body>
</html>
